package Test4;
import java.util.Scanner;
/**
 *
 * @author 29284
 * @since 2024/11/29 21:37
 */
public class StringDemo {
    public static void main(String[] args) {
       int  money;
       Scanner sc = new Scanner(System.in);
        while(true) {
            //输入金额
            System.out.println("输入转换金额：");
            money = sc.nextInt();
            if (money >= 0 && money <= 9999999) {
                //定义数组
                String[] str = new String[10];
                str[0] = "零";
                str[1] = "壹";
                str[2] = "贰";
                str[3] = "叁";
                str[4] = "肆";
                str[5] = "伍";
                str[6] = "陆";
                str[7] = "柒";
                str[8] = "捌";
                str[9] = "玖";
                //定义变量来拼接
                String moneyStr = "";
                while (true) {
                    //获取各位数字
                    int ge = money % 10;
                    String capitalNumber = str[ge];
                    moneyStr = capitalNumber + moneyStr;
                    money = money / 10;
                    if (money == 0) {
                        break;
                    }
                }
                //补齐位数
                int count = 7 - moneyStr.length();
                for (int i = 0; i < count; i++) {
                    moneyStr = "零" + moneyStr;
                }
                //插入单位
                String[] arr = {"佰", "拾", "万", "仟", "佰", "拾", "元"};
                String result = "";
                for (int i = 0; i < arr.length; i++) {
                    char ch = moneyStr.charAt(i);
                    result = result + ch + arr[i];
                }
                System.out.println(result);
                break;
            } else if (money > 9999999) {
                System.out.println("金额太大，请重新输入！");
                break;
            } else {
                System.out.println("金额太小，请重新输入！");
                break;
            }
        }
    }
}
